import datetime
from pymongo import MongoClient
from conf.settings import CLOUDMONITOR_MONGODB, CLOUDMONITOR_DB

conn = MongoClient(CLOUDMONITOR_MONGODB)
db = conn[CLOUDMONITOR_DB]


def read():
    with open('./data.txt', 'w', encoding='utf-8') as f:
        for item in db.news.find():
            item.pop('_id')
            f.write(str(item))
            f.write('\n')


def write():
    with open('./data.txt', 'r', encoding='utf-8') as f:
        data = f.read()

    data_list = [eval(item) for item in data.split('\n') if item]


def main():
    write()


if __name__ == '__main__':
    main()
